// src/api/employee.ts
import request from '@/utils/request';
// 导入我们将在模型层创建的类型
import type { IEmployee, IEmployeePageResult, IEmployeePageQuery, IEmployeeEditForm, IEmployeeAddForm,IPasswordEditDTO } from '@/types/employee';

/**
 * 员工登录
 * @param data - 登录凭证
 */
export const login = (data: { username: string; password: string }) => {
  return request({
    url: '/employee/login',
    method: 'post',
    data
  });
};

/**
 * 退出登录
 */
export const userLogout = () => {
  return request({
    url: '/employee/logout',
    method: 'post'
  });
};

/**
 * 修改密码
 * @param data - 包含 empId, oldPassword, newPassword
 */
export const updateEmployeePasswords = (data: IPasswordEditDTO) => {
  return request({
    url: '/employee/editPassword',
    method: 'put',
    data // Body 参数使用 data 属性
  });
};
/**
 * 员工分页查询
 * @param params - 查询参数
 */
export const getEmployeePage = (params: IEmployeePageQuery) => {
  return request<ICategoryPageResult>({
    url: '/employee/page',
    method: 'get',
    params
  });
};

/**
 * 新增员工
 * @param data - 员工信息
 */
export const addEmployee = (data: IEmployeeAddForm) => {
  return request({
    url: '/employee',
    method: 'post',
    data
  });
};

/**
 * 编辑员工信息
 * @param data - 员工信息
 */
export const editEmployee = (data: IEmployeeEditForm) => {
  return request({
    url: '/employee',
    method: 'put',
    data
  });
};

/**
 * 根据id查询员工
 * @param id - 员工id
 */
export const getEmployeeById = (id: number) => {
  return request<IEmployee>({
    url: `/employee/${id}`,
    method: 'get'
  });
};

/**
 * 启用、禁用员工账号
 * @param params - 包含 status 和 id
 */
export const updateEmployeeStatus = (params: { status: 0 | 1; id: number }) => {
  return request({
    url: `/employee/status/${params.status}`,
    method: 'post',
    params: { id: params.id }
  });
};

/**
 * 修改密码
 * @param data - 密码信息
 */
export const updateEmployeePassword = (data: { empId: number; oldPassword: string; newPassword: string }) => {
  return request({
    url: '/employee/editPassword',
    method: 'put',
    data
  });
};
